<?php
	class CategoriasController extends AppController{
		
		public $helpers = array ('Html','Form');
		
		function index(){
			$this->set('categorias', $this->Categoria->find('all'));
		}
	
	
		public function add() {
			if ($this->request->is('post')) {
				if ($this->Categoria->save($this->request->data)) {
					$this->redirect(array('action' => 'index'));
				}
			}
		}
		
		function delete($id) {
			if (!$this->request->is('post')) {
				throw new MethodNotAllowedException();
			}
			if ($this->Categoria->delete($id)) {
				$this->redirect(array('action' => 'index'));
			}
		}
		
		function edit($id = null) {
			$this->Categoria->id = $id;
			if ($this->request->is('get')) {
				$this->request->data = $this->Categoria->read();
			} else {
				if ($this->Categoria->save($this->request->data)) {
					$this->Session->setFlash('Modificaciones guardadas correctamente','success');
					$this->redirect(array('action' => 'index'));
				}
				else{
					$this->Session->setFlash('Error al guardar cambios!!');
					$this->redirect(array('action' => 'index'));
				}
			}
		}
	}
?>